package com.sicong.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicong.admin.entity.Permission;
import com.sicong.admin.mapper.PermissionMapper;
import com.sicong.admin.service.PermissionService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chenww
 * @since 2020-11-25
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {

    @Override
    public Boolean savePermission(Permission permission) {
        if (StringUtils.isEmpty(permission.getPid())) {
            permission.setPid(0L);
        }
        baseMapper.insert(permission);
        return Boolean.TRUE;
    }

    @Override
    public List<String> findPermissionsByRoleId(List<Long> roleIds) {
        return baseMapper.findPermissionsByRoleId(roleIds).stream()
                .filter(permission -> !StringUtils.isEmpty(permission)).collect(Collectors.toList());
    }

}
